package com.kx.game.center.manager;

import com.kx.game.center.global.GSServices;
import com.kx.game.center.redis.RedisConstant;

import com.kx.game.center.utils.StringUtils;
import java.util.Set;

public class NewFriendManager {

    //保存地区的玩家信息
    public void saveRegionUser(String region, String userId, String oldRegion) throws Exception {
        if(StringUtils.isEmpty(region))
            return;
        //清除
        if (oldRegion != null && !oldRegion.equals("") && !oldRegion.equals(region))
            GSServices.redisManager.setRemove(RedisConstant.REGION_USER + "_" + region, userId);
        //更新
        GSServices.redisManager.setAdd(RedisConstant.REGION_USER + "_" + region, userId);
    }

    //随机抽取地区的玩家信息
    public Set<String> getRegionUsers(String region, int num) throws Exception {
        return GSServices.redisManager.getRandomInfo(RedisConstant.REGION_USER + "_" + region, num, String.class);
    }

    //保存在线玩家信息
    public void saveOnLineUser(String userId) throws Exception {
        GSServices.redisManager.setAdd(RedisConstant.ONLINE_USER, userId);
    }

    //移除在线玩家信息
    public void removeOnLineUser(String userId) throws Exception {
        GSServices.redisManager.setRemove(RedisConstant.ONLINE_USER, userId);
    }

    //随机抽取在线玩家信息
    public Set<String> getOnLineUsers(int num) throws Exception {
        Set<String> randomInfo = GSServices.redisManager.getRandomInfo(RedisConstant.ONLINE_USER, num, String.class);
        return randomInfo;
    }

}
